# /**
# * Copyright (c) 2022 Beijing Jiaotong University
# * PhotLab is licensed under [Open Source License].
# * You can use this software according to the terms and conditions of the [Open Source License].
# *
# * You may obtain a copy of [Open Source License] at: [https://open.source.license/]
# *
# * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# *
# * See the [Open Source License] for more details.
# */
# /**
# * Author: Shihao Xie
# * Created: Jul. 5, 2022
# * Supported by: National Key Research and Development Program of China
# */
from phot_server.manager.engine_manager import EngineManager
from phot_server.manager.graph_manager import GraphManager
from phot_server.manager.grid_manager import GridManager
from phot_server.manager.library_manager import LibraryManager
from phot_server.manager.project_manager import ProjectManager
from phot_server.server_config.global_config import global_config_dict
from phot_server.server_config.minio_config import minio_config_dict
from phot_server.utils.phot_logger import get_log_file_end


# gettext instructions
# D:/Python/Tools/i18n/
# pygettext.py -d engine -o locales/engine.po service/engine_service.py
# msgfmt.py -o ./locales/cn/LC_MESSAGES/service.mo ./locales/cn/LC_MESSAGES/service
# msgfmt.py -o ./locales/en/LC_MESSAGES/service.mo ./locales/en/LC_MESSAGES/service
#
# This class is a container that contain all interface function
#
class MainHandler:
    def __init__(self):
        self.project_manager = ProjectManager()
        self.graph_manager = GraphManager()
        self.library_manager = LibraryManager()
        self.grid_manager = GridManager()
        self.engine_manager = EngineManager()
        self.headers = {}
        self.project_container = {}
        self.languages = {}
        self.server_config_dict = {}
        self.server_config_dict.update(global_config_dict)
        self.server_config_dict.update(minio_config_dict)
        self.log_file_pointer = {"phot_server": get_log_file_end("phot_server"),
                                 "root": get_log_file_end("root"),
                                 "phot": get_log_file_end("phot"),
                                 "phot_engine": get_log_file_end("phot_engine")}

    def set_headers(self, headers):
        self.headers = headers
        self.set_language(self.headers.get("lang", "cn"))

    def set_language(self, language):
        self._ = self.languages[language].gettext
